<?php
   require_once "controller.php";
   require_once "Model/foodModel.php";
   class FoodController extends Controller{
   	   function __construct(){
            parent::__construct();
   	   	   $this->mod=new FoodModel();
   	   }
       //显示菜品列表
   	   public function listfoods(){
        $fooddata=$this->mod->getFoodList();//调用模型层的方法获得数据
      
   	     $this->assign("foods",$fooddata);
        
           $this->display();
   	   }
       //显示添加菜品的页面
       public function foodform(){
        $this->display();
       }
       //添加菜品，写入数据库
       public function addfood(){
        $result=$this->mod->addFoodInfo();
        if($result==true){
          echo '添加成功！<br>';
          header("refresh:3;index.php?c=food&m=listfoods");
          echo ' <a href="index.php?c=food&m=listfoods">如果没有跳转，请点这里跳转</a>';
        }
        else{
          header("location:index.php?c=food&m=listfoods");
        }
      }//addfood end
      //修改菜品信息
      public function editfood(){
        $data=$this->mod->getFoodbyID();
        $this->assign('food',$data);
        $this->display();

      }
      public function updatefood(){
        $result=$this->mod->updateFoodInfo();
        if($result==true){
          echo '更新成功！<br>';
          header("refresh:3;index.php?c=food&m=listfoods");
          echo ' <a href="index.php?c=food&m=listfoods">如果没有跳转，请点这里跳转</a>';
        }

      }
      public function delfood(){
        $result=$this->mod->delFoodInfo();
        if($result==true){
          echo '更新成功！<br>';
          header("refresh:3;index.php?c=food&m=listfoods");
          echo ' <a href="index.php?c=food&m=listfoods">如果没有跳转，请点这里跳转</a>';
        }

      }
   }//class Foodcontroller end


?>